package com.myframe.www.main;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.myframe.www.R;
import com.myframe.www.base.BaseFragment;
import com.myframe.www.example.JcvdActivity;
import com.myframe.www.example.MaterialeditTextActivity;
import com.myframe.www.recycle.RecycleAgainActivity;
import com.myframe.www.recycle.RecycleHomeActivity;
import com.yong.android.framework.dialog.BaseDialog;
import com.yong.android.framework.utils.EasyToast;
import com.yong.android.framework.utils.log.SLog;

import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * A simple {@link Fragment} subclass.
 */
public class ShopFragment extends BaseFragment {
    private Consumer<String> consumer;
    private Observer<String> observer;

    public ShopFragment() {
        // Required empty public constructor
    }


    @Override
    protected int getFragmentLayout() {
        return R.layout.fragment_shop;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        helloWorldSimple();
        helloWorldSimplex();
    }

    //    简单版本
    private void helloWorldSimple() {
        //创建消费者，消费者接受一个String类型的事件
        consumer = new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                SLog.e(s);
            }
        };
    }

    //复杂版本
    private void helloWorldSimplex() {
        observer = new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
            }

            @Override
            public void onNext(String value) {
                SLog.e(TAG, value);
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        };
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.btn_ease, R.id.btn_dialog, R.id.btn_recycle,R.id.btn_recycle_again,R.id.btn_materialedittext,R.id.btn_jcvc})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_ease:
                break;
            case R.id.btn_dialog:
                final BaseDialog dialog = new BaseDialog(getContext());
                dialog.showConfirmCancelButtonDialog("是否确定退出", "确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        EasyToast.showToast(getActivity(),"点击确定");
                        dialog.dismissDialog();
                    }
                }, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        EasyToast.showToast(getActivity(),"点击取消");
                        dialog.dismissDialog();
                    }
                });
                break;
            case R.id.btn_recycle:
                RecycleHomeActivity.start(getActivity());
                break;
            case R.id.btn_recycle_again:
                RecycleAgainActivity.start(getActivity());
                break;
            case R.id.btn_materialedittext:
                MaterialeditTextActivity.start(getActivity());
                break;

            case R.id.btn_jcvc:
                JcvdActivity.start(getActivity());
                break;
        }
    }
}
